<template>
	<u-list @scrolltolower="scrolltolower">
		<!-- 轮播图 -->
		<!-- #ifndef APP-NVUE || MP-TOUTIAO -->
		<view class="u-demo-block">
			<u-swiper height="180" indicator interval="2000" :list="list3" previousMargin="30" nextMargin="30" circular :autoplay="false" radius="5" bgColor="#ffffff"></u-swiper>
			<!-- 疫苗专区 -->
			<view class="vaccineList">
				<view v-for="(item, index) in vaccineList" :key="index" @click="goVaccine(item, index)">
					<image class="vaccineList-img" :src="item.image" mode=""></image>
					<text>{{ item.title }}</text>
				</view>
			</view>
			<!-- 体检区 -->
			<view class="physical">
				<view class="physical-view" v-for="(item, index) in physicalList" :key="index" @click="goPhysical(index)">
					<text class="physical-title">{{ item.title }}</text>
					<text class="physical-lable">{{ item.describe }}</text>
					<image mode="widthFix" :src="item.image"></image>
				</view>
			</view>
			<!-- 热门挂号区 -->
			<view class="hotRegister">
				<u-divider text="热门挂号" textSize="20" lineColor="#d8d8e6" textColor="#222222" textPosition="left"></u-divider>
				<!-- <text class="hotRegister-title">热门挂号</text> -->
				<view>
					<u-grid :border="true" @click="click">
						<!-- :bgColor="item.background"  不加背景色了  不好看-->
						<u-grid-item v-for="(item, index) in hotRegisterList" :key="index">
							<image class="hotRegister-img" :src="item.image" mode="aspectFit"></image>
							<text class="grid-text">{{ item.title }}</text>
						</u-grid-item>
					</u-grid>
					<u-toast ref="uToast" />
				</view>
			</view>
			<!-- 健康自测 -->
			<view class="healthTest">
				<u-divider text="健康自测" textSize="20" lineColor="#d8d8e6" textColor="#222222" textPosition="left"></u-divider>
				<view class="healthTest-bigview">
					<view class="healthTest-view" v-for="(item, index) in newHealthTestList" :key="index" @click="goTest(item)">
						<view class="heal-box">
							<text class="heal-title">{{ item.name }}</text>
							<br />
							<text class="heal-lable">{{ item.question }}题 / {{ item.minute }}分钟</text>
							<view class="heal-people">
								<text class="top-num">{{ item.number_of_people }}</text>
								<text class="top-min">人测过</text>
							</view>
						</view>
						<image class="top-img" :src="item.image" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<!-- <u-skeleton rows="10"  animate :loading="vaccineList.length == 0 ? true : false"></u-skeleton> -->
		<!-- #endif -->
	</u-list>
</template>
<script>
import { getIndexApi } from '../../utils/api.js';
export default {
	data() {
		return {
			//轮播图数据
			list3: ['https://cdn.uviewui.com/uview/swiper/swiper3.png', 'https://cdn.uviewui.com/uview/swiper/swiper2.png', 'https://cdn.uviewui.com/uview/swiper/swiper1.png'],
			//疫苗列表数据
			vaccineList: [],
			//体检数据
			physicalList: [],
			//热门挂号数据
			hotRegisterList: [],
			//健康自测数据
			healthTestList: []
		};
	},
	methods: {
		scrolltolower() {},
		//获取页面数据
		async getIndexData() {
			const res = await getIndexApi();
			console.log(res);
			this.vaccineList = res.data[0].vaccine;
			this.physicalList = res.data[1].reserve;
			this.hotRegisterList = res.data[2].popular;
			this.healthTestList = res.data[3].self_test;
		},
		click(name) {
			this.$refs.uToast.success(`点击了第${name}个`);
		},
		// 去疫苗项
		goVaccine(item, index) {
			console.log(item, index);
			if (index === 0) {
				uni.navigateTo({
					url: '../component/xinguanOrder/xinguanOrder'
				});
			} else if (index === 1) {
				uni.navigateTo({
					url: '../../pages/component/HPVOrder/HPVOrder'
				});
			} else if (index === 2) {
				uni.navigateTo({
					url: '../../pages/component/NATOrder/NATOrder'
				});
			} else if (index === 3) {
				uni.navigateTo({
					url: '../../pages/component/counsel/counsel'
				});
			}
		},
		// 去体检测试
		goPhysical(index) {
			uni.navigateTo({
				url: '../component/healthExam/List/List'
			});
		},
		// 去测试
		goTest(item) {
			if (item.name == '失眠程度测评') {
				uni.navigateTo({
					url: '/pages/component/personTest/topic/topic?flag=002&name=' + item.name
				});
			} else {
				uni.navigateTo({
					url: '/pages/component/personTest/topic/topic?flag=001&name=' + item.name
				});
			}
		}
	},
	computed: {
		newHealthTestList() {
			let arr = [];
			this.healthTestList.forEach((item, index) => {
				if (index == 0 || index == 2) {
					arr.push(item);
				}
			});
			return arr;
		}
	},
	//声明周期挂完再请求
	created() {
		this.getIndexData();
	}
};
</script>
<style lang="less">
page {
	background-color: #fafafa;
}
//疫苗区
.vaccineList {
	margin-top: 20rpx;
	display: flex;
	background-color: #ffffff;
	justify-content: space-around;
	view {
		width: 160rpx;
		height: 160rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		.vaccineList-img {
			width: 80rpx;
			height: 80rpx;
			margin-bottom: 16rpx;
		}
	}
}
// 体检区
.physical {
	background-color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 10rpx;
	margin-top: 20rpx;
}
.physical-view {
	position: relative;
	height: 200rpx;
	width: 48%;
}
.physical-view image {
	width: 150rpx;
	display: block;
	position: absolute;
	bottom: 0;
	right: 20rpx;
}
.physical view:nth-child(1) text:nth-child(1) {
	color: #0042ff;
}
.physical view:nth-child(2) text:nth-child(1) {
	color: #dc6200;
}
.physical view:nth-child(1) {
	background-image: linear-gradient(to right, #d7dfff 10%, #5a9fff 100%);
	border-radius: 20rpx;
}
.physical view:nth-child(2) {
	background-image: linear-gradient(to right, #ffdbb4 10%, #ffc56b 100%);
	border-radius: 20rpx;
}
.physical-title {
	position: absolute;
	top: 20rpx;
	left: 20rpx;
	font-size: 40rpx;
}
.physical-lable {
	font-size: 30rpx;
	color: #ffffff;
	position: absolute;
	top: 90rpx;
	left: 20rpx;
}
// 热门挂号区
.hotRegister {
	background-color: #ffffff;
	margin-top: 20rpx;
	.hotRegister-title {
		font-size: 40rpx;
		margin-left: 20rpx;
	}
	.hotRegister-img {
		width: 100rpx;
		height: 100rpx;
		margin-bottom: 6rpx;
	}
	.u-grid {
		padding: 10rpx;
		.u-grid-item {
			padding: 10rpx;
		}
	}
}
// 健康自测
.healthTest {
	background-color: #ffffff;
	margin-top: 10rpx;
	margin-bottom: 10rpx;

	.healthTest-bigview {
		display: flex;
		justify-content: space-between;
		.healthTest-view {
			width: 48%;
			height: 250rpx;
			margin: 10rpx;
			border-radius: 20rpx;
			overflow: hidden;
			position: relative;
			.top-img {
				width: 170rpx;
				height: 180rpx;
				display: block;
				position: absolute;
				right: 0;
				bottom: 0;
			}
			.top-lable {
				color: #a6abb0;
			}
			.heal-box {
				position: absolute;
				left: 20rpx;
				top: 35rpx;

				.heal-people {
					display: flex;
					align-items: baseline;
					padding-top: 30rpx;
					.top-num {
						font-size: 35rpx;
						padding-right: 10rpx;
					}
					.top-min {
						font-size: 25rpx;
					}
				}
			}
		}
	}
}
</style>
